package com.ccys.cms.controller.marketing;

import com.ccys.cms.service.marketing.AdvertiseWebService;
import com.ccys.common.constants.ContextConstants;
import com.ccys.common.util.Kit;
import com.ccys.common.vo.ResponseResult;
import com.ccys.db.dto.marketing.AdvertiseDTO;
import com.ccys.db.entity.TblAdvertisement;
import com.ccys.db.vo.marketing.AdvertiseDetailWebVO;
import com.ccys.db.vo.marketing.AdvertiseWebVO;
import io.swagger.annotations.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@Api(tags = "市场设置-广告")
@RequestMapping("marketing")
@CrossOrigin(methods = {RequestMethod.GET, RequestMethod.POST, RequestMethod.DELETE, RequestMethod.PUT}) // 开启跨域访问允许
@SuppressWarnings("unchecked")
public class AdvertiseWebController {

    @Autowired
    private AdvertiseWebService advertiseWebService;

    @GetMapping("advertise")
    @ApiOperation("获取列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "advertiseTitle", value = "advertiseTitle", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseCountries", value = "国家ID", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "endDate", value = "endDate(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startDate", value = "startDate(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseStatus", value = "advertiseStatus", required = false, dataType = "string", paramType = "query"),

        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startTime", value = "开始时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "endTime", value = "结束时间(格式 yyyy-mm-dd)", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "orderByStr", value = "排序字段（后端返回的字段  asc升序，desc 降序,加上end后缀。示例（createdOn降序排 则传值 createdOn descend））",paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = AdvertiseWebVO.class)
    })
    public ResponseResult listObjectsCms(HttpServletRequest request, HttpServletResponse response, @ApiIgnore AdvertiseDTO dto) {
        return this.advertiseWebService.listObjectsCms(request, response, dto);
    }

    @GetMapping("advertise/detail")
    @ApiOperation("查询详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "对象id", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC,response = AdvertiseDetailWebVO.class)
    })
    public ResponseResult getDetail(@ApiIgnore AdvertiseDTO dto) {
        return this.advertiseWebService.getDetail(dto);
    }


    @PostMapping("advertise")
    @ApiOperation("添加")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "advertiseCountries", value = "多个国家以英文逗号隔开", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "advertiseDescription", value = "advertiseDescription", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "advertiseDispOrder", value = "advertiseDispOrder", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "advertiseImage", value = "advertiseImage", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "advertiseStatus", value = "advertiseStatus", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "advertiseTitle", value = "advertiseTitle", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "advertiseTransitionTiming", value = "advertiseTransitionTiming", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "endDate", required = false, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startDate", value = "startDate", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult save(@ApiIgnore TblAdvertisement entity) {
        entity.setId(null);
        return this.advertiseWebService.change(entity);
    }


    @PutMapping("advertise")
    @ApiOperation("编辑")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseCountries", value = "多个国家以英文逗号隔开", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseDescription", value = "advertiseDescription", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseDispOrder", value = "advertiseDispOrder", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseImage", value = "advertiseImage", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseStatus", value = "advertiseStatus", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseTitle", value = "advertiseTitle", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "advertiseTransitionTiming", value = "advertiseTransitionTiming", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "endDate", value = "endDate", required = false, dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "startDate", value = "startDate", required = false, dataType = "string", paramType = "query"),
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult edit(@ApiIgnore TblAdvertisement entity) {
        Kit.allParamValid(entity, "id");
        return this.advertiseWebService.change(entity);
    }


    @DeleteMapping("advertise")
    @ApiOperation("删除")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "ID号", required = true, dataType = "string", paramType = "query")
    })
    @ApiResponses({
        @ApiResponse(code = 411, message = ContextConstants.DESC_411),
        @ApiResponse(code = 200, message = ContextConstants.MODEL_DESC)
    })
    public ResponseResult delete(TblAdvertisement dto) {
        Kit.allParamValid(dto, "id");
        return this.advertiseWebService.delete(dto);
    }

}